package com.administrator.scoreManageSys.service.impl;

import com.administrator.scoreManageSys.mapper.course.ClassMangeMapper;
import com.administrator.scoreManageSys.service.ClassMangeService;
import com.administrator.scoreManageSys.utils.ResultUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author zsh
 * @date 2022/03/23/ 10:50
 */
@Service
public class ClassMangeServiceImpl implements ClassMangeService {
    @Resource
    private ClassMangeMapper classMangeMapper;

    @Resource
    private ResultUtils resultUtils;

    /**
     * 获取班级列表
     *
     * @return 班级列表
     * @param pageNum  当前页
     * @param pageSize 页大小
     * @param name 班级名
     */
    @Override
    public JSONObject classList(Integer pageNum, Integer pageSize, String name) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list = classMangeMapper.classList(name);
        PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(list);
        return resultUtils.resultSuccessData(pageInfo);
    }

    /**
     * 添加班级
     *
     * @param name         班级名称
     * @param classTeacher 班级的班主任
     * @param userId 操作人id
     * @return 操作结果
     */
    @Override
    public JSONObject classAdd(String name,  Long classTeacher, Long userId) {
        long createTime = System.currentTimeMillis();
        classMangeMapper.classAdd(name, classTeacher,userId,createTime);
        return resultUtils.resultSuccess();
    }

    /**
     * 根据id删除班级
     *
     * @param id 删除班级id
     * @return 操作结果
     */
    @Override
    public JSONObject classDelete(Long id) {
        classMangeMapper.classDelete(id);
        return resultUtils.resultSuccess();
    }

    /**
     * 修改班级
     *
     * @param name         修改的班级名称
     * @param id           修改的班级id
     * @param classTeacher 班主任id
     * @return 操作结果
     */
    @Override
    public JSONObject classUpdate(String name,  Long id, Long classTeacher) {
        classMangeMapper.classUpdate(id, name,  classTeacher);
        return resultUtils.resultSuccess();
    }

    /**
     * 获取所有班主任名单
     *
     * @return 教师名单
     */
    @Override
    public JSONObject classTeacherList() {
        JSONArray list= classMangeMapper.classTeacherList();
        return resultUtils.resultSuccessData(list);
    }

    /**
     * 根据班级id获取科目
     *
     * @param classId 班级id
     * @return 科目
     */
    @Override
    public JSONObject classSubjectList(Integer classId) {
        JSONArray list= classMangeMapper.classSubjectList(classId);
        return resultUtils.resultSuccessData(list);
    }

}
